package com.cn.file;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

/**
 * 查询结果
 */
public class GetMessageResult {

    private final List<SelectMappedBufferResult> messageMapedList = new ArrayList<>(100);

    //存放数据块
    private final List<ByteBuffer> msgList = new ArrayList<>(100);

    private GetMessageStatus messageStatus;

    private long minOffset;

    private long maxOffset;

    private long nextOffset;

    private long totalMsgSize;

    public GetMessageResult() {
    }

    public GetMessageResult(GetMessageStatus messageStatus, long minOffset, long maxOffset) {
        this.messageStatus = messageStatus;
        this.minOffset = minOffset;
        this.maxOffset = maxOffset;
    }

    public void addMessage(SelectMappedBufferResult mappedBufferResult) {
        this.messageMapedList.add(mappedBufferResult);
        this.msgList.add(mappedBufferResult.getByteBuffer());
        this.totalMsgSize += mappedBufferResult.getSize();
    }

    public void addMessageMapedList(SelectMappedBufferResult mappedBufferResult) {
        this.messageMapedList.add(mappedBufferResult);
    }

    public void release() {
        for (SelectMappedBufferResult result : messageMapedList) {
            result.release();
        }
    }

    public void addMsgList(ByteBuffer byteBuffer) {
        this.msgList.add(byteBuffer);
    }

    public List<SelectMappedBufferResult> getMessageMapedList() {
        return messageMapedList;
    }

    public List<ByteBuffer> getMsgList() {
        return msgList;
    }

    public GetMessageStatus getMessageStatus() {
        return messageStatus;
    }

    public void setMessageStatus(GetMessageStatus messageStatus) {
        this.messageStatus = messageStatus;
    }

    public long getMinOffset() {
        return minOffset;
    }

    public GetMessageResult setMinOffset(long minOffset) {
        this.minOffset = minOffset;
        return this;
    }

    public long getMaxOffset() {
        return maxOffset;
    }

    public GetMessageResult setMaxOffset(long maxOffset) {
        this.maxOffset = maxOffset;
        return this;
    }

    public long getNextOffset() {
        return nextOffset;
    }

    public void setNextOffset(long nextOffset) {
        this.nextOffset = nextOffset;
    }

    public long getTotalMsgSize() {
        return totalMsgSize;
    }

    public void setTotalMsgSize(long totalMsgSize) {
        this.totalMsgSize = totalMsgSize;
    }
}
